#ifndef __DOUBLE_LIST_H__
#define __DOUBLE_LIST_H__

#include <stdio.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * user customer node type define like flow:
 * struct my_node
 * {
 *    double_list_node_t node; //the struct must stay first place of this struct my_node
 *    uint32_t value;
 * };
 */

/**define like this, is avoid more small memory alloc and then memory fragmentation */
typedef struct double_list_node_s
{
    struct double_list_node_s* next;
    struct double_list_node_s* prev;
}double_list_node_t;


typedef struct single_list_s
{
    uint32_t node_count;
    void(*nodeFree)(void* node);
    /**
     * -1: node1 <  node2
     *  0: node1 == node2
     *  1: node2 >  node2
     */
    int (*compare)(double_list_node_t* node1, double_list_node_t* node2);
    double_list_node_t* head;
    double_list_node_t* tail; /** for fast push back operation */
}single_list_t;





#ifdef __cplusplus
}
#endif // __cplusplus

#endif // __DOUBLE_LIST_H__
